package shop.core.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import shop.services.front.activity.ActivityService;
import shop.services.front.activity.bean.Activity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


/**
 * Created by wzl on 2018/1/29.
 */
@Component
public class ActivityStatusTask implements Runnable{
    @Autowired
    private ActivityService activityService;
    @Override
    public void run() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String today="";
        try{
            today = sdf.format(date);
        }catch(Exception e){}
        Activity activity =new Activity();
        List<Activity> activityList=activityService.selectList(activity);
        for(Activity activityInfo :activityList){
            if(today.compareTo(activityInfo.getStartDate())<0){
                activityInfo.setStatus("1");
            }else if(today.compareTo(activityInfo.getEndDate())>0){
                activityInfo.setStatus("3");
            }else{
                activityInfo.setStatus("2");
            }
            activityService.update(activityInfo);
        }
    }
}
